<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Mongo,Mongo索引," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.0" />






<meta name="description" content="Mongo存储引擎1、Mongo存储引擎决定了数据如何保存到内存或者磁盘的细节，不同的存储引擎可以针对不同的工作负载，比如偏重优化读性能的存储引擎和偏重于写性能的存储引擎。2、Mongo的复制集允许混合使用不同的存储引擎。但是混用存储引擎也会有额外的问题如：  the oplog on each member may need to be sized differently to account">
<meta name="keywords" content="Mongo,Mongo索引">
<meta property="og:type" content="article">
<meta property="og:title" content="Mongo查询分析以及索引规则一">
<meta property="og:url" content="https://gitee.com/shuhao/2017/12/07/Mongo查询分析以及索引规则/index.html">
<meta property="og:site_name" content="Niki">
<meta property="og:description" content="Mongo存储引擎1、Mongo存储引擎决定了数据如何保存到内存或者磁盘的细节，不同的存储引擎可以针对不同的工作负载，比如偏重优化读性能的存储引擎和偏重于写性能的存储引擎。2、Mongo的复制集允许混合使用不同的存储引擎。但是混用存储引擎也会有额外的问题如：  the oplog on each member may need to be sized differently to account">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-01-02T11:53:56.367Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Mongo查询分析以及索引规则一">
<meta name="twitter:description" content="Mongo存储引擎1、Mongo存储引擎决定了数据如何保存到内存或者磁盘的细节，不同的存储引擎可以针对不同的工作负载，比如偏重优化读性能的存储引擎和偏重于写性能的存储引擎。2、Mongo的复制集允许混合使用不同的存储引擎。但是混用存储引擎也会有额外的问题如：  the oplog on each member may need to be sized differently to account">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Mist',
    sidebar: {"position":"right","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://gitee.com/shuhao/2017/12/07/Mongo查询分析以及索引规则/"/>





  <title> Mongo查询分析以及索引规则一 | Niki </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cb9f0585e406f878cb2f29c89ad3cdb7";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Niki</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">天道酬勤</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-categories"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/shuhao/blog/2017/12/07/Mongo查询分析以及索引规则/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Fang ShuHao">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/head.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Niki">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Mongo查询分析以及索引规则一
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-07T08:51:38+08:00">
                2017-12-07
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Mongo/" itemprop="url" rel="index">
                    <span itemprop="name">Mongo</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>Mongo存储引擎<br>1、<br>Mongo存储引擎决定了数据如何保存到内存或者磁盘的细节，不同的存储引擎可以针对不同的工作负载，比如偏重优化读性能的存储引擎和偏重于写性能的存储引擎。<br>2、<br>Mongo的复制集允许混合使用不同的存储引擎。但是混用存储引擎也会有额外的问题如：</p>
<ul>
<li>the oplog on each member may need to be sized differently to account for differences in throughput between different storage engines.<br>不同存储引擎之间oplog之间的差异</li>
<li>recovery from backups may become more complex if your backup captures data files from MongoDB: you may need to maintain backups for each storage engine.<br>在不同的存储引擎之间恢复数据的差异。</li>
</ul>
<p>3、Mongo两种引擎<br>MMAP</p>
<ul>
<li>在高负载的写入和读取环境下性能表现良好<br>the oplog on each member may need to be sized differently to account for differences in throughput between different storage engines.<br>recovery from backups may become more complex if your backup captures data files from MongoDB: you may need to maintain backups for each storage engine.</li>
</ul>
<p>WiredTiger（3.2版本后新引擎）</p>
<ul>
<li>提供了文档级别的并发锁</li>
<li>新的压缩方式<br>WiredTiger provides a document-level concurrency model, checkpointing, and compression, among other features</li>
</ul>
<h2 id="Mongo查询分析"><a href="#Mongo查询分析" class="headerlink" title="Mongo查询分析"></a>Mongo查询分析</h2><p>在Mongo中，使用explain对查询进行分析进而优化。</p>
<h3 id="explain共有三种模式"><a href="#explain共有三种模式" class="headerlink" title="explain共有三种模式"></a>explain共有三种模式</h3><h4 id="1-queryPlanner"><a href="#1-queryPlanner" class="headerlink" title="1. queryPlanner"></a>1. queryPlanner</h4><p>   Mongo默认的explain模式,采用db.collection.find().explain()采用的就是这种模式。该模式下，Mongo不会真正进行query语句查询，而是针对query语句进行执行计划分析选出winning plan<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; db.people.explain().find()</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line"></span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&gt; db.people.find().explain()</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line"></span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="2-executionStats"><a href="#2-executionStats" class="headerlink" title="2. executionStats"></a>2. executionStats</h4><p>该模式是Mongo查询的执行状态。<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; db.people.explain(&quot;executionStats&quot;).find()</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line"></span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 50475,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 450,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;nReturned&quot; : 50475,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 380,</span><br><span class="line">                        &quot;works&quot; : 50477,</span><br><span class="line">                        &quot;advanced&quot; : 50475,</span><br><span class="line">                        &quot;needTime&quot; : 1,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 394,</span><br><span class="line">                        &quot;restoreState&quot; : 394,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="3-allPlansExecution"><a href="#3-allPlansExecution" class="headerlink" title="3. allPlansExecution"></a>3. allPlansExecution</h4><p>该模式类似queryPlanner + executionStats<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; db.people.explain(&quot;allPlansExecution&quot;).find()</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line"></span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 50475,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 13,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;nReturned&quot; : 50475,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 10,</span><br><span class="line">                        &quot;works&quot; : 50477,</span><br><span class="line">                        &quot;advanced&quot; : 50475,</span><br><span class="line">                        &quot;needTime&quot; : 1,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 394,</span><br><span class="line">                        &quot;restoreState&quot; : 394,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;allPlansExecution&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>可以看出，三种查询模式中，executionStats模式必queryPlanner模式多了executionStats返回值； 而allPlansExecution模式比executionStats模式多了allPlansExecution返回值。</p>
<p>explain执行的语句在Mongo中，并不会真正执行，而是模拟执行。如db.people.explain().update()，并不会去修改Mongo中的数据！</p>
<h3 id="explain需要关注的参数"><a href="#explain需要关注的参数" class="headerlink" title="explain需要关注的参数"></a>explain需要关注的参数</h3><p>使用explain来分析我们的查询时，我们通常使用的模式为：ExecutionStats，且关注的返回值有：</p>
<ul>
<li>executionSuccess 执行是否成功</li>
<li>nReturned 执行返回记录数</li>
<li>executionTimeMillis 执行使用的时间</li>
<li>totalkeysExamined 执行共扫描的索引数</li>
<li><p>totalDocsExamined 执行扫描的文档数</p>
</li>
<li><p>stage 执行使用的策略。</p>
<ol>
<li>COLLSCAN 全表扫描</li>
<li>SORT 在内存中排序</li>
<li>FETCH 根据索引去检索指定的document</li>
<li>IXSCAN 索引扫描</li>
<li>LIMIT 使用limit限制返回数</li>
<li>SKIP 使用skip跳过</li>
<li>COUNT count 运算</li>
<li>COUNTSCAN 使用count，没用index</li>
<li>COUNT_INDEX 使用count时，用到了index</li>
<li>IDHACK 针对id进行查询</li>
<li>SUBPLA 未使用索引的$or查询</li>
<li>TEXT 使用全文索引进行查询</li>
<li>PROJECTION 查询限定返回字段</li>
<li>SHARDING_FILTER Mongo对分片数据进行查询</li>
</ol>
</li>
<li><p>keyPattern 如果使用了索引，则匹配的是那个索引，值为索引的名称</p>
</li>
<li>isMultiKey 是否为多值索引，在数组上创建的索引</li>
<li>direction [forward, backward]创建索引时会指定索引的顺序，该查询和索引采用相同的顺序则为forward，逆序则为backward</li>
<li>indexBounds 查询使用的索引边界</li>
</ul>
<h4 id="stage模式分析"><a href="#stage模式分析" class="headerlink" title="stage模式分析"></a>stage模式分析</h4><p>当我们查询的时候，我们希望看到的stage有：<br>IXCAN, IDHACK, FETCH+IXCAN, COUNT_INDEX</p>
<p>不希望看到的stage有：<br>COLLSCAN, SORT, COUNTSCAN, SKIP(不合理的skip), SUBPLA(没有用到索引的$or)</p>
<h2 id="设置Mongo慢查询，用来分析查询比较慢的语句"><a href="#设置Mongo慢查询，用来分析查询比较慢的语句" class="headerlink" title="设置Mongo慢查询，用来分析查询比较慢的语句"></a>设置Mongo慢查询，用来分析查询比较慢的语句</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; db.setProfilingLevel(1,20)</span><br><span class="line">&#123; &quot;was&quot; : 0, &quot;slowms&quot; : 100, &quot;ok&quot; : 1 &#125;</span><br><span class="line"></span><br><span class="line">&gt; db.getProfilingStatus()</span><br><span class="line">&#123; &quot;was&quot; : 1, &quot;slowms&quot; : 20 &#125;</span><br><span class="line"></span><br><span class="line">#查询慢查询日志</span><br><span class="line">db.system.profiling.find()</span><br></pre></td></tr></table></figure>
<p>Mongo的慢查询保存在system.profile这个collection中。是一个盖子集合。（可通过isCapped()来判断collection是否为盖子集合）</p>
<blockquote>
<p>参考<br><a href="https://docs.mongodb.com/manual/reference/explain-results/index.html" target="_blank" rel="external">MongoDB explain Result 文档</a><br><a href="http://www.mongoing.com/eshu_explain3" target="_blank" rel="external">MongoDB执行计划详解</a></p>
</blockquote>
<p>查询索引<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; db.people.getIndexes()</span><br><span class="line">[</span><br><span class="line">        &#123;</span><br><span class="line">                &quot;v&quot; : 2,</span><br><span class="line">                &quot;key&quot; : &#123;</span><br><span class="line">                        &quot;_id&quot; : 1</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;name&quot; : &quot;_id_&quot;,</span><br><span class="line">                &quot;ns&quot; : &quot;m201.people&quot;</span><br><span class="line">        &#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure></p>
<p>查看执行计划<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; db.people.find().explain()</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line"></span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&gt; var explain = db.people.explain(&quot;executionStats&quot;)</span><br><span class="line"></span><br><span class="line">#查询first_name</span><br><span class="line">&gt; explain.find(&#123;first_name:&quot;Daniel&quot;&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line">                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;filter&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                        &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 450,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 24,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;filter&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                        &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;nReturned&quot; : 450,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 30,</span><br><span class="line">                        &quot;works&quot; : 50477,</span><br><span class="line">                        &quot;advanced&quot; : 450,</span><br><span class="line">                        &quot;needTime&quot; : 50026,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 394,</span><br><span class="line">                        &quot;restoreState&quot; : 394,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#查询first_name 并且 limit</span><br><span class="line">&gt; explain.find(&#123;first_name:&quot;Daniel&quot;&#125;).limit(2)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line">                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;LIMIT&quot;,</span><br><span class="line">                        &quot;limitAmount&quot; : 2,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                                &quot;filter&quot; : &#123;</span><br><span class="line">                                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                                &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                        &#125;</span><br><span class="line">                                &#125;,</span><br><span class="line">                                &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 2,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 0,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 129,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;LIMIT&quot;,</span><br><span class="line">                        &quot;nReturned&quot; : 2,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 0,</span><br><span class="line">                        &quot;works&quot; : 131,</span><br><span class="line">                        &quot;advanced&quot; : 2,</span><br><span class="line">                        &quot;needTime&quot; : 128,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 1,</span><br><span class="line">                        &quot;restoreState&quot; : 1,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;limitAmount&quot; : 2,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                                &quot;filter&quot; : &#123;</span><br><span class="line">                                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                                &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                        &#125;</span><br><span class="line">                                &#125;,</span><br><span class="line">                                &quot;nReturned&quot; : 2,</span><br><span class="line">                                &quot;executionTimeMillisEstimate&quot; : 0,</span><br><span class="line">                                &quot;works&quot; : 130,</span><br><span class="line">                                &quot;advanced&quot; : 2,</span><br><span class="line">                                &quot;needTime&quot; : 128,</span><br><span class="line">                                &quot;needYield&quot; : 0,</span><br><span class="line">                                &quot;saveState&quot; : 1,</span><br><span class="line">                                &quot;restoreState&quot; : 1,</span><br><span class="line">                                &quot;isEOF&quot; : 0,</span><br><span class="line">                                &quot;invalidates&quot; : 0,</span><br><span class="line">                                &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                                &quot;docsExamined&quot; : 129</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#查询first_name 并且 sort</span><br><span class="line">&gt; explain.find(&#123;first_name:&quot;Daniel&quot;&#125;).sort(&#123;first_name:1&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line">                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;SORT&quot;,</span><br><span class="line">                        &quot;sortPattern&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;SORT_KEY_GENERATOR&quot;,</span><br><span class="line">                                &quot;inputStage&quot; : &#123;</span><br><span class="line">                                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                                        &quot;filter&quot; : &#123;</span><br><span class="line">                                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                                        &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                                &#125;</span><br><span class="line">                                        &#125;,</span><br><span class="line">                                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 450,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 48,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;SORT&quot;,</span><br><span class="line">                        &quot;nReturned&quot; : 450,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 50,</span><br><span class="line">                        &quot;works&quot; : 50929,</span><br><span class="line">                        &quot;advanced&quot; : 450,</span><br><span class="line">                        &quot;needTime&quot; : 50478,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 398,</span><br><span class="line">                        &quot;restoreState&quot; : 398,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;sortPattern&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;memUsage&quot; : 178515,</span><br><span class="line">                        &quot;memLimit&quot; : 33554432,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;SORT_KEY_GENERATOR&quot;,</span><br><span class="line">                                &quot;nReturned&quot; : 450,</span><br><span class="line">                                &quot;executionTimeMillisEstimate&quot; : 40,</span><br><span class="line">                                &quot;works&quot; : 50478,</span><br><span class="line">                                &quot;advanced&quot; : 450,</span><br><span class="line">                                &quot;needTime&quot; : 50027,</span><br><span class="line">                                &quot;needYield&quot; : 0,</span><br><span class="line">                                &quot;saveState&quot; : 398,</span><br><span class="line">                                &quot;restoreState&quot; : 398,</span><br><span class="line">                                &quot;isEOF&quot; : 1,</span><br><span class="line">                                &quot;invalidates&quot; : 0,</span><br><span class="line">                                &quot;inputStage&quot; : &#123;</span><br><span class="line">                                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                                        &quot;filter&quot; : &#123;</span><br><span class="line">                                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                                        &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                                &#125;</span><br><span class="line">                                        &#125;,</span><br><span class="line">                                        &quot;nReturned&quot; : 450,</span><br><span class="line">                                        &quot;executionTimeMillisEstimate&quot; : 0,</span><br><span class="line">                                        &quot;works&quot; : 50477,</span><br><span class="line">                                        &quot;advanced&quot; : 450,</span><br><span class="line">                                        &quot;needTime&quot; : 50026,</span><br><span class="line">                                        &quot;needYield&quot; : 0,</span><br><span class="line">                                        &quot;saveState&quot; : 398,</span><br><span class="line">                                        &quot;restoreState&quot; : 398,</span><br><span class="line">                                        &quot;isEOF&quot; : 1,</span><br><span class="line">                                        &quot;invalidates&quot; : 0,</span><br><span class="line">                                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#根据last_name排序</span><br><span class="line">&gt; explain.find().sort(&#123;last_name:1&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line"></span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;SORT&quot;,</span><br><span class="line">                        &quot;sortPattern&quot; : &#123;</span><br><span class="line">                                &quot;last_name&quot; : 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;SORT_KEY_GENERATOR&quot;,</span><br><span class="line">                                &quot;inputStage&quot; : &#123;</span><br><span class="line">                                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 50475,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 216,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;SORT&quot;,</span><br><span class="line">                        &quot;nReturned&quot; : 50475,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 190,</span><br><span class="line">                        &quot;works&quot; : 100954,</span><br><span class="line">                        &quot;advanced&quot; : 50475,</span><br><span class="line">                        &quot;needTime&quot; : 50478,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 789,</span><br><span class="line">                        &quot;restoreState&quot; : 789,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;sortPattern&quot; : &#123;</span><br><span class="line">                                &quot;last_name&quot; : 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;memUsage&quot; : 19977916,</span><br><span class="line">                        &quot;memLimit&quot; : 33554432,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;SORT_KEY_GENERATOR&quot;,</span><br><span class="line">                                &quot;nReturned&quot; : 50475,</span><br><span class="line">                                &quot;executionTimeMillisEstimate&quot; : 60,</span><br><span class="line">                                &quot;works&quot; : 50478,</span><br><span class="line">                                &quot;advanced&quot; : 50475,</span><br><span class="line">                                &quot;needTime&quot; : 2,</span><br><span class="line">                                &quot;needYield&quot; : 0,</span><br><span class="line">                                &quot;saveState&quot; : 789,</span><br><span class="line">                                &quot;restoreState&quot; : 789,</span><br><span class="line">                                &quot;isEOF&quot; : 1,</span><br><span class="line">                                &quot;invalidates&quot; : 0,</span><br><span class="line">                                &quot;inputStage&quot; : &#123;</span><br><span class="line">                                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                                        &quot;nReturned&quot; : 50475,</span><br><span class="line">                                        &quot;executionTimeMillisEstimate&quot; : 0,</span><br><span class="line">                                        &quot;works&quot; : 50477,</span><br><span class="line">                                        &quot;advanced&quot; : 50475,</span><br><span class="line">                                        &quot;needTime&quot; : 1,</span><br><span class="line">                                        &quot;needYield&quot; : 0,</span><br><span class="line">                                        &quot;saveState&quot; : 789,</span><br><span class="line">                                        &quot;restoreState&quot; : 789,</span><br><span class="line">                                        &quot;isEOF&quot; : 1,</span><br><span class="line">                                        &quot;invalidates&quot; : 0,</span><br><span class="line">                                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line">&gt;</span><br><span class="line"></span><br><span class="line">#查询first_name last_name</span><br><span class="line">&gt; explain.find(&#123;first_name:&quot;Daniel&quot;,&quot;last_name&quot; : &quot;Turner&quot;&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line">                        &quot;$and&quot; : [</span><br><span class="line">                                &#123;</span><br><span class="line">                                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                                &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                        &#125;</span><br><span class="line">                                &#125;,</span><br><span class="line">                                &#123;</span><br><span class="line">                                        &quot;last_name&quot; : &#123;</span><br><span class="line">                                                &quot;$eq&quot; : &quot;Turner&quot;</span><br><span class="line">                                        &#125;</span><br><span class="line">                                &#125;</span><br><span class="line">                        ]</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;filter&quot; : &#123;</span><br><span class="line">                                &quot;$and&quot; : [</span><br><span class="line">                                        &#123;</span><br><span class="line">                                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                                        &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                                &#125;</span><br><span class="line">                                        &#125;,</span><br><span class="line">                                        &#123;</span><br><span class="line">                                                &quot;last_name&quot; : &#123;</span><br><span class="line">                                                        &quot;$eq&quot; : &quot;Turner&quot;</span><br><span class="line">                                                &#125;</span><br><span class="line">                                        &#125;</span><br><span class="line">                                ]</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 1,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 24,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;filter&quot; : &#123;</span><br><span class="line">                                &quot;$and&quot; : [</span><br><span class="line">                                        &#123;</span><br><span class="line">                                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                                        &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                                &#125;</span><br><span class="line">                                        &#125;,</span><br><span class="line">                                        &#123;</span><br><span class="line">                                                &quot;last_name&quot; : &#123;</span><br><span class="line">                                                        &quot;$eq&quot; : &quot;Turner&quot;</span><br><span class="line">                                                &#125;</span><br><span class="line">                                        &#125;</span><br><span class="line">                                ]</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;nReturned&quot; : 1,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 30,</span><br><span class="line">                        &quot;works&quot; : 50477,</span><br><span class="line">                        &quot;advanced&quot; : 1,</span><br><span class="line">                        &quot;needTime&quot; : 50475,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 394,</span><br><span class="line">                        &quot;restoreState&quot; : 394,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&gt; explain.find(&#123;first_name:&#123;$gt:&quot;Nicholas&quot;&#125;&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line">                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                &quot;$gt&quot; : &quot;Nicholas&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;filter&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                        &quot;$gt&quot; : &quot;Nicholas&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 12957,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 24,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;filter&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                        &quot;$gt&quot; : &quot;Nicholas&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;nReturned&quot; : 12957,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 10,</span><br><span class="line">                        &quot;works&quot; : 50477,</span><br><span class="line">                        &quot;advanced&quot; : 12957,</span><br><span class="line">                        &quot;needTime&quot; : 37519,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 394,</span><br><span class="line">                        &quot;restoreState&quot; : 394,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line">&gt; explain.find(&#123;first_name:&#123;$gt:&quot;Nicholas&quot;&#125;&#125;).sort(&#123;first_name:1&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line">                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                &quot;$gt&quot; : &quot;Nicholas&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;SORT&quot;,</span><br><span class="line">                        &quot;sortPattern&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;SORT_KEY_GENERATOR&quot;,</span><br><span class="line">                                &quot;inputStage&quot; : &#123;</span><br><span class="line">                                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                                        &quot;filter&quot; : &#123;</span><br><span class="line">                                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                                        &quot;$gt&quot; : &quot;Nicholas&quot;</span><br><span class="line">                                                &#125;</span><br><span class="line">                                        &#125;,</span><br><span class="line">                                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 12957,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 80,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;SORT&quot;,</span><br><span class="line">                        &quot;nReturned&quot; : 12957,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 80,</span><br><span class="line">                        &quot;works&quot; : 63436,</span><br><span class="line">                        &quot;advanced&quot; : 12957,</span><br><span class="line">                        &quot;needTime&quot; : 50478,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 496,</span><br><span class="line">                        &quot;restoreState&quot; : 496,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;sortPattern&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;memUsage&quot; : 5125961,</span><br><span class="line">                        &quot;memLimit&quot; : 33554432,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;SORT_KEY_GENERATOR&quot;,</span><br><span class="line">                                &quot;nReturned&quot; : 12957,</span><br><span class="line">                                &quot;executionTimeMillisEstimate&quot; : 20,</span><br><span class="line">                                &quot;works&quot; : 50478,</span><br><span class="line">                                &quot;advanced&quot; : 12957,</span><br><span class="line">                                &quot;needTime&quot; : 37520,</span><br><span class="line">                                &quot;needYield&quot; : 0,</span><br><span class="line">                                &quot;saveState&quot; : 496,</span><br><span class="line">                                &quot;restoreState&quot; : 496,</span><br><span class="line">                                &quot;isEOF&quot; : 1,</span><br><span class="line">                                &quot;invalidates&quot; : 0,</span><br><span class="line">                                &quot;inputStage&quot; : &#123;</span><br><span class="line">                                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                                        &quot;filter&quot; : &#123;</span><br><span class="line">                                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                                        &quot;$gt&quot; : &quot;Nicholas&quot;</span><br><span class="line">                                                &#125;</span><br><span class="line">                                        &#125;,</span><br><span class="line">                                        &quot;nReturned&quot; : 12957,</span><br><span class="line">                                        &quot;executionTimeMillisEstimate&quot; : 20,</span><br><span class="line">                                        &quot;works&quot; : 50477,</span><br><span class="line">                                        &quot;advanced&quot; : 12957,</span><br><span class="line">                                        &quot;needTime&quot; : 37519,</span><br><span class="line">                                        &quot;needYield&quot; : 0,</span><br><span class="line">                                        &quot;saveState&quot; : 496,</span><br><span class="line">                                        &quot;restoreState&quot; : 496,</span><br><span class="line">                                        &quot;isEOF&quot; : 1,</span><br><span class="line">                                        &quot;invalidates&quot; : 0,</span><br><span class="line">                                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>创建索引<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; db.people.createIndex(&#123;last_name:1, first_name:1, employer:1, job:1&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;createdCollectionAutomatically&quot; : false,</span><br><span class="line">        &quot;numIndexesBefore&quot; : 1,</span><br><span class="line">        &quot;numIndexesAfter&quot; : 2,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&gt; db.people.getIndexes()</span><br><span class="line">[</span><br><span class="line">        &#123;</span><br><span class="line">                &quot;v&quot; : 2,</span><br><span class="line">                &quot;key&quot; : &#123;</span><br><span class="line">                        &quot;_id&quot; : 1</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;name&quot; : &quot;_id_&quot;,</span><br><span class="line">                &quot;ns&quot; : &quot;m201.people&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">                &quot;v&quot; : 2,</span><br><span class="line">                &quot;key&quot; : &#123;</span><br><span class="line">                        &quot;last_name&quot; : 1,</span><br><span class="line">                        &quot;first_name&quot; : 1,</span><br><span class="line">                        &quot;employer&quot; : 1,</span><br><span class="line">                        &quot;job&quot; : 1</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;name&quot; : &quot;last_name_1_first_name_1_employer_1_job_1&quot;,</span><br><span class="line">                &quot;ns&quot; : &quot;m201.people&quot;</span><br><span class="line">        &#125;</span><br><span class="line">]</span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure></p>
<p>创建索引后查询<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; explain.find(&#123;first_name:&quot;Daniel&quot;&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line">                        &quot;first_name&quot; : &#123;</span><br><span class="line">                                &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;filter&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                        &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 450,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 23,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 0,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 50475,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;COLLSCAN&quot;,</span><br><span class="line">                        &quot;filter&quot; : &#123;</span><br><span class="line">                                &quot;first_name&quot; : &#123;</span><br><span class="line">                                        &quot;$eq&quot; : &quot;Daniel&quot;</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;,</span><br><span class="line">                        &quot;nReturned&quot; : 450,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 20,</span><br><span class="line">                        &quot;works&quot; : 50477,</span><br><span class="line">                        &quot;advanced&quot; : 450,</span><br><span class="line">                        &quot;needTime&quot; : 50026,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 394,</span><br><span class="line">                        &quot;restoreState&quot; : 394,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                        &quot;docsExamined&quot; : 50475</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&gt; explain.find(&#123;&quot;last_name&quot;:&quot;Turner&quot;&#125;)</span><br><span class="line">&#123;</span><br><span class="line">        &quot;queryPlanner&quot; : &#123;</span><br><span class="line">                &quot;plannerVersion&quot; : 1,</span><br><span class="line">                &quot;namespace&quot; : &quot;m201.people&quot;,</span><br><span class="line">                &quot;indexFilterSet&quot; : false,</span><br><span class="line">                &quot;parsedQuery&quot; : &#123;</span><br><span class="line">                        &quot;last_name&quot; : &#123;</span><br><span class="line">                                &quot;$eq&quot; : &quot;Turner&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;winningPlan&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;FETCH&quot;,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;IXSCAN&quot;,</span><br><span class="line">                                &quot;keyPattern&quot; : &#123;</span><br><span class="line">                                        &quot;last_name&quot; : 1,</span><br><span class="line">                                        &quot;first_name&quot; : 1,</span><br><span class="line">                                        &quot;employer&quot; : 1,</span><br><span class="line">                                        &quot;job&quot; : 1</span><br><span class="line">                                &#125;,</span><br><span class="line">                                &quot;indexName&quot; : &quot;last_name_1_first_name_1_employer_1_job_1&quot;,</span><br><span class="line">                                &quot;isMultiKey&quot; : false,</span><br><span class="line">                                &quot;multiKeyPaths&quot; : &#123;</span><br><span class="line">                                        &quot;last_name&quot; : [ ],</span><br><span class="line">                                        &quot;first_name&quot; : [ ],</span><br><span class="line">                                        &quot;employer&quot; : [ ],</span><br><span class="line">                                        &quot;job&quot; : [ ]</span><br><span class="line">                                &#125;,</span><br><span class="line">                                &quot;isUnique&quot; : false,</span><br><span class="line">                                &quot;isSparse&quot; : false,</span><br><span class="line">                                &quot;isPartial&quot; : false,</span><br><span class="line">                                &quot;indexVersion&quot; : 2,</span><br><span class="line">                                &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                                &quot;indexBounds&quot; : &#123;</span><br><span class="line">                                        &quot;last_name&quot; : [</span><br><span class="line">                                                &quot;[\&quot;Turner\&quot;, \&quot;Turner\&quot;]&quot;</span><br><span class="line">                                        ],</span><br><span class="line">                                        &quot;first_name&quot; : [</span><br><span class="line">                                                &quot;[MinKey, MaxKey]&quot;</span><br><span class="line">                                        ],</span><br><span class="line">                                        &quot;employer&quot; : [</span><br><span class="line">                                                &quot;[MinKey, MaxKey]&quot;</span><br><span class="line">                                        ],</span><br><span class="line">                                        &quot;job&quot; : [</span><br><span class="line">                                                &quot;[MinKey, MaxKey]&quot;</span><br><span class="line">                                        ]</span><br><span class="line">                                &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                &quot;rejectedPlans&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;executionStats&quot; : &#123;</span><br><span class="line">                &quot;executionSuccess&quot; : true,</span><br><span class="line">                &quot;nReturned&quot; : 163,</span><br><span class="line">                &quot;executionTimeMillis&quot; : 1,</span><br><span class="line">                &quot;totalKeysExamined&quot; : 163,</span><br><span class="line">                &quot;totalDocsExamined&quot; : 163,</span><br><span class="line">                &quot;executionStages&quot; : &#123;</span><br><span class="line">                        &quot;stage&quot; : &quot;FETCH&quot;,</span><br><span class="line">                        &quot;nReturned&quot; : 163,</span><br><span class="line">                        &quot;executionTimeMillisEstimate&quot; : 0,</span><br><span class="line">                        &quot;works&quot; : 164,</span><br><span class="line">                        &quot;advanced&quot; : 163,</span><br><span class="line">                        &quot;needTime&quot; : 0,</span><br><span class="line">                        &quot;needYield&quot; : 0,</span><br><span class="line">                        &quot;saveState&quot; : 1,</span><br><span class="line">                        &quot;restoreState&quot; : 1,</span><br><span class="line">                        &quot;isEOF&quot; : 1,</span><br><span class="line">                        &quot;invalidates&quot; : 0,</span><br><span class="line">                        &quot;docsExamined&quot; : 163,</span><br><span class="line">                        &quot;alreadyHasObj&quot; : 0,</span><br><span class="line">                        &quot;inputStage&quot; : &#123;</span><br><span class="line">                                &quot;stage&quot; : &quot;IXSCAN&quot;,</span><br><span class="line">                                &quot;nReturned&quot; : 163,</span><br><span class="line">                                &quot;executionTimeMillisEstimate&quot; : 0,</span><br><span class="line">                                &quot;works&quot; : 164,</span><br><span class="line">                                &quot;advanced&quot; : 163,</span><br><span class="line">                                &quot;needTime&quot; : 0,</span><br><span class="line">                                &quot;needYield&quot; : 0,</span><br><span class="line">                                &quot;saveState&quot; : 1,</span><br><span class="line">                                &quot;restoreState&quot; : 1,</span><br><span class="line">                                &quot;isEOF&quot; : 1,</span><br><span class="line">                                &quot;invalidates&quot; : 0,</span><br><span class="line">                                &quot;keyPattern&quot; : &#123;</span><br><span class="line">                                        &quot;last_name&quot; : 1,</span><br><span class="line">                                        &quot;first_name&quot; : 1,</span><br><span class="line">                                        &quot;employer&quot; : 1,</span><br><span class="line">                                        &quot;job&quot; : 1</span><br><span class="line">                                &#125;,</span><br><span class="line">                                &quot;indexName&quot; : &quot;last_name_1_first_name_1_employer_1_job_1&quot;,</span><br><span class="line">                                &quot;isMultiKey&quot; : false,</span><br><span class="line">                                &quot;multiKeyPaths&quot; : &#123;</span><br><span class="line">                                        &quot;last_name&quot; : [ ],</span><br><span class="line">                                        &quot;first_name&quot; : [ ],</span><br><span class="line">                                        &quot;employer&quot; : [ ],</span><br><span class="line">                                        &quot;job&quot; : [ ]</span><br><span class="line">                                &#125;,</span><br><span class="line">                                &quot;isUnique&quot; : false,</span><br><span class="line">                                &quot;isSparse&quot; : false,</span><br><span class="line">                                &quot;isPartial&quot; : false,</span><br><span class="line">                                &quot;indexVersion&quot; : 2,</span><br><span class="line">                                &quot;direction&quot; : &quot;forward&quot;,</span><br><span class="line">                                &quot;indexBounds&quot; : &#123;</span><br><span class="line">                                        &quot;last_name&quot; : [</span><br><span class="line">                                                &quot;[\&quot;Turner\&quot;, \&quot;Turner\&quot;]&quot;</span><br><span class="line">                                        ],</span><br><span class="line">                                        &quot;first_name&quot; : [</span><br><span class="line">                                                &quot;[MinKey, MaxKey]&quot;</span><br><span class="line">                                        ],</span><br><span class="line">                                        &quot;employer&quot; : [</span><br><span class="line">                                                &quot;[MinKey, MaxKey]&quot;</span><br><span class="line">                                        ],</span><br><span class="line">                                        &quot;job&quot; : [</span><br><span class="line">                                                &quot;[MinKey, MaxKey]&quot;</span><br><span class="line">                                        ]</span><br><span class="line">                                &#125;,</span><br><span class="line">                                &quot;keysExamined&quot; : 163,</span><br><span class="line">                                &quot;seeks&quot; : 1,</span><br><span class="line">                                &quot;dupsTested&quot; : 0,</span><br><span class="line">                                &quot;dupsDropped&quot; : 0,</span><br><span class="line">                                &quot;seenInvalidated&quot; : 0</span><br><span class="line">                        &#125;</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;serverInfo&quot; : &#123;</span><br><span class="line">                &quot;host&quot; : &quot;YZJC1606-0218&quot;,</span><br><span class="line">                &quot;port&quot; : 27017,</span><br><span class="line">                &quot;version&quot; : &quot;3.4.7&quot;,</span><br><span class="line">                &quot;gitVersion&quot; : &quot;cf38c1b8a0a8dca4a11737581beafef4fe120bcd&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/Mongo/" rel="tag"># Mongo</a>
          
            <a href="/blog/tags/Mongo索引/" rel="tag"># Mongo索引</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2017/12/04/Mongo复制集二/" rel="next" title="Mongo复制集二">
                <i class="fa fa-chevron-left"></i> Mongo复制集二
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2017/12/08/springboot整合Motan/" rel="prev" title="springboot整合Motan">
                springboot整合Motan <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNjY5NS8xMzIzMA=="></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/head.jpg"
               alt="Fang ShuHao" />
          <p class="site-author-name" itemprop="name">Fang ShuHao</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives">
                <span class="site-state-item-count">135</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories">
                <span class="site-state-item-count">35</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags">
                <span class="site-state-item-count">93</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Mongo查询分析"><span class="nav-number">1.</span> <span class="nav-text">Mongo查询分析</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#explain共有三种模式"><span class="nav-number">1.1.</span> <span class="nav-text">explain共有三种模式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-queryPlanner"><span class="nav-number">1.1.1.</span> <span class="nav-text">1. queryPlanner</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-executionStats"><span class="nav-number">1.1.2.</span> <span class="nav-text">2. executionStats</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-allPlansExecution"><span class="nav-number">1.1.3.</span> <span class="nav-text">3. allPlansExecution</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#explain需要关注的参数"><span class="nav-number">1.2.</span> <span class="nav-text">explain需要关注的参数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#stage模式分析"><span class="nav-number">1.2.1.</span> <span class="nav-text">stage模式分析</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#设置Mongo慢查询，用来分析查询比较慢的语句"><span class="nav-number">2.</span> <span class="nav-text">设置Mongo慢查询，用来分析查询比较慢的语句</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Fang ShuHao</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  



  
  

  

  

  

  


  

</body>
</html>
